package com.itboye.mengwu.app.ui.main;

import java.text.SimpleDateFormat;
import java.util.Observable;
import java.util.Observer;

import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.itboye.core.object.BaseActivity;
import com.itboye.core.object.ResultEntity;
import com.itboye.mengwu.R;
import com.itboye.mengwu.data.model.OrderDetailBean;
import com.itboye.mengwu.data.presenter.OrderPresenter;

public class TuiKuanXiangQingActivity extends BaseActivity implements Observer {

	ImageView back;
	TextView txt_title, refundProgress, refundType, refundReason, refundTime,
			refundCode, refundTime2, refundDesc,refundMoney;
	String orderCode;
	OrderPresenter orderPresenter;
	OrderDetailBean orderDetailBean;

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub
		ResultEntity entity = handlerError(data);
		if (entity != null) {
			orderDetailBean = (OrderDetailBean) entity.getData();
			if (orderDetailBean != null) {
				if (orderDetailBean.getCsStatus().equals("2")) {
					refundProgress.setText("待处理");
				} else if (orderDetailBean.getCsStatus().equals("3")) {
					refundProgress.setText("已处理");
				}
				if (orderDetailBean.getRefundType().equals("1")) {
					refundType.setText("退款");
				} else if (orderDetailBean.getRefundType().equals("2")) {
					refundType.setText("退货");
				} else if (orderDetailBean.getRefundType().equals("3")) {
					refundType.setText("退款退货");
				}
				refundReason.setText(orderDetailBean.getReason());
				refundTime
						.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
								.format(Long.parseLong(orderDetailBean
										.getRefundTime()) * 1000));
				refundTime2
						.setText(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
								.format(Long.parseLong(orderDetailBean
										.getRefundTime()) * 1000));
				refundCode.setText(orderDetailBean.getOrderCode());
				refundDesc.setText(orderDetailBean.getNote());
				refundMoney.setText(orderDetailBean.getRefundMoney());
			}
		}
		try {
			closeProgressDialog();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.activity_tuikuanxiangqing;
	}

	@Override
	public void onMyCreate() {
		// TODO Auto-generated method stub
		orderPresenter = new OrderPresenter(this);
		showProgressDialog("加载中", true);
		orderCode = getIntent().getStringExtra("orderId");
		orderPresenter.getXiangQing(orderCode);
		back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		txt_title.setText("退款详情");
	}

}
